package com.x.xiaoshuo.ui.read;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;

import com.x.xiaoshuo.R;


public class LoadingDialog extends Dialog {

    private LoadingDialog(Context context, int theme) {
        super(context, theme);
    }

    public void onWindowFocusChanged(boolean hasFocus) {
        ImageView imageView = (ImageView) findViewById(R.id.loading);
        RotateAnimation rotateAnimation = new RotateAnimation(360, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setRepeatCount(100);
        rotateAnimation.setDuration(2000);
        imageView.startAnimation(rotateAnimation);
    }

    public static LoadingDialog getAppProgress(Context context, boolean cancelable,
                                               OnCancelListener cancelListener) {
        LoadingDialog appProgress = new LoadingDialog(context, com.x.mvp.R.style.Custom_Progress);
        appProgress.setTitle("");
        appProgress.setContentView(R.layout.loading_book);
        appProgress.setCancelable(cancelable);
        appProgress.setOnCancelListener(cancelListener);
        appProgress.getWindow().getAttributes().gravity = Gravity.CENTER;
        WindowManager.LayoutParams lp = appProgress.getWindow().getAttributes();
        lp.dimAmount = 0.2f;
        appProgress.getWindow().setAttributes(lp);
        return appProgress;
    }
}